function getSum(arr, n, target) {
    const res = [];
    let sum = 0;
  
    function backtrack(cur, start) {
      if (cur.length === n) {
        if (sum === target) {
          res.push([...cur]);
        }
        return;
      }
  
      for (let i = start; i < arr.length; i++) {
        sum += arr[i];
        cur.push(arr[i]);
        backtrack(cur, i + 1);
        cur.pop();
        sum -= arr[i];
      }
    }
  
    backtrack([], 0);
    return res;
  }
  
  // 示例
  const arr = [1, 2, 3, 4, 5, 6];
  const n = 3;
  const target = 7;
  const res = getSum(arr, 2, target);
  console.log(res); // [[1, 2, 4], [1, 3, 3], [2, 2, 3]]